#!/bin/ash
# Coded by Vishnu Pradeep
# email: intermedia.vishnu@gmail.com

# Talk is cheap, show me the code

#-----------------------------------------------------------------
modesense="00 26 00 00" # Set the Mode Sense id         	 -
pno="1"                 # Partition No          	         -
path="/mnt/usb"        	# where to mount the drive		 -
#----------------------------------------------------------------- 

fnFindDrive(){
  if [ $(grep -i 'sda' ./google -c) = "1" ]; then
   echo found at sda
   fnMount "sda"
  elif [ $(grep -i 'sdb' ./google -c) = "1" ]; then
   echo found at sdb
   fnMount "sdb"
  elif [ $(grep -i 'sdc' ./google -c) = "1" ]; then
   echo found at sdc
   fnMount "sdc"
  elif [ $(grep -i 'sdd' ./google -c) = "1" ]; then
   echo found at sdd
   fnMount "sdd"
  fi
}

fnShell(){
 count=$(dmesg | grep -i "Mode Sense: $modesense" -c)
 echo $count
 if [ $count -gt "0" ]; then
  thisline=$(dmesg | grep -i "Mode Sense: $modesense"| tail -1) 
  echo $thisline > google 
  fnFindDrive
 else
  echo error
 fi
}

fnMount(){
 mount /dev/$1$pno $path
}

fnShell
